#include "stm32f10x.h"                  // Device header

static GPIO_TypeDef* gpiox;
static uint16_t pin;
static uint32_t rcc_APB2Periph;
static u8 isInit = 0; //是否初始化、按下的键值

/**
	初始化传感器
*/
void sensor_init(uint32_t RCC_APB2Periph,GPIO_TypeDef* GPIOx,uint16_t Pin){
  gpiox = GPIOx;
	pin = Pin;
	rcc_APB2Periph = RCC_APB2Periph;
	RCC_APB2PeriphClockCmd(rcc_APB2Periph,ENABLE);
	GPIO_InitTypeDef type;
	type.GPIO_Mode = GPIO_Mode_IPU; //需要上拉输入，按键未按时默认高电平;
	type.GPIO_Pin =  pin; 
	type.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(gpiox,&type);
	isInit = 1;
}

/**
	读取传感器的水平
*/
u8 read_sensor_level(void){
	if(isInit == 1){
		return GPIO_ReadInputDataBit(gpiox,pin);
	}
	return 0;
}
